<template>
	<view>
    <view class="address-choose-box" v-if="JSON.stringify(address) === '{}'">
      <button type="primary" size="mini" @click="chooseAddress">请选择收货地址+</button>
    </view>
		<!-- 1. 收货地址区 -->
    <view class="address-box" v-else>
      <!-- 1.1 收货人姓名及电话区 -->
      <view class="row1">
        <view class="row1-left">
          <!-- 1.1.1 收货人 -->
          <view class="username">
            收货人：<text>{{address.userName}}</text>
          </view>
        </view>
        <!-- 1.1.2 收货电话 -->
        <view class="row1-right">
          <view class="phone">
            收货电话：<text>{{address.telNumber}}</text>
          </view>
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view>
      </view>
      <!-- 1.2 收货地址区 -->
      <view class="row2">
        <view class="row2-left">
          收货地址：
        </view>
        <view class="row2-right">
          {{addstr}}
        </view>
      </view>
    </view>
    <!-- 2. 分隔条图片区 -->
    <image src="/static/cart_border@2x.png" class="address-img"></image>
	</view>
</template>

<script>
  import {mapState,mapMutations,mapGetters} from 'vuex'
	export default {
		data() {
			return {
				// address:{}  
			};
		},
    computed:{
      ...mapState("m_user",["address"]),   // 引入后才可以用this.address方式引用
      ...mapGetters("m_user",["addstr"]),  // 此时通过getters方法取得计算属性的值，这样在视图中就可以直接使用了
    },
    methods:{
       ...mapMutations("m_user",["updateAddress"]),
      // 1. 选择地址对话框
      async chooseAddress(){
        const [err,succ] = await uni.chooseAddress().catch(err => err)
        console.log(err)
        if(err == null && succ.errMsg === 'chooseAddress:ok'){
          // this.address = succ
          this.updateAddress(succ)
        }
      }
    }
	}
</script>

<style lang="scss">
.address-img{
  width:100%;
  height: 5px;
}
.address-box{
  height: 72px;
  display: flex;
  padding:0 3px;
  flex-direction: column;
  justify-content: center;
  .row1{
    display: flex;
    justify-content: space-between;
    .row1-left{
      
      .username{
        
      }
    }
    .row1-right{
      display: flex;
      .phone{
        margin-right: 5px;
      }
    }
  }
  .row2{
    display: flex;
    align-items: center;
    .row2-left{
     white-space: nowrap;
    }
    .row2-right{
      
    }
  }
}
.address-choose-box{
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
